///*****************************************
//  Copyright (C) 2009-2014
//  ITE Tech. Inc. All Rights Reserved
//  Proprietary and Confidential
///*****************************************
//   @file   <edid.c>
//   @author Jau-Chih.Tseng@ite.com.tw
//   @date   2012/07/24
//   @fileversion: HDMIRX_SAMPLE_2.18
//******************************************/


//#include "Mcu.h"
//#include "IO.h"
#include "TimerProcess.h"
#include "EDID.h"
//#include "VGA.h"
#ifdef Debug_message
#define EDID_Dump
#endif

#ifdef _COPY_EDID_

BYTE MeshCheckSum = 0 ;
BYTE PrevMeshCheckSum = 0xA5 ;


BOOL bSupport1080p = FALSE ;
// #define SUPPORT_NOEDID_MONITOR

// BYTE code DTD_640x480_60P[] = { 0xD5,0x09,0x80,0xA0,0x20,0xE0,0x2D,0x10,0x10,0x60,0xA2,0x00,0xA0,0x78,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_720x480_60P[] = { 0x8C,0x0A,0xD0,0x8A,0x20,0xE0,0x2D,0x10,0x10,0x3E,0x96,0x00,0xB4,0x78,0x00,0x00,0x00,0x18} ;
BYTE code DTD_1280x720_60P[] = { 0x1A,0x1D,0x00,0x72,0x51,0xD0,0x1E,0x20,0x6E,0x28,0x55,0x00,0x40,0xB4,0x10,0x00,0x00,0x1E} ;
BYTE code DTD_1920x1080_60I[] = { 0x1A,0x1D,0x80,0x18,0x71,0x1C,0x16,0x20,0x58,0x2C,0x25,0x00,0xE0,0x87,0x10,0x00,0x00,0x9E} ;
// BYTE code DTD_720x480_60I[] = { 0x46,0x05,0xD0,0x8A,0x20,0xF0,0x16,0x00,0x13,0x3E,0x43,0x00,0xB4,0x3C,0x00,0x00,0x00,0x98} ;
// BYTE code DTD_720x240_60P[] = { 0x46,0x05,0xD0,0x8A,0x20,0xF0,0x16,0x00,0x13,0x3E,0x43,0x00,0xB4,0x3C,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_1440x480_60I[] = { 0x8C,0x0A,0xA0,0x14,0x51,0xF0,0x16,0x00,0x26,0x7C,0x53,0x00,0x68,0x3C,0x10,0x00,0x00,0x98} ;
// BYTE code DTD_1440x240_60P[] = { 0x8C,0x0A,0xA0,0x14,0x51,0xF0,0x17,0x00,0x26,0x7C,0x53,0x00,0x68,0x3C,0x10,0x00,0x00,0x18} ;
// BYTE code DTD_2880x480_60I[] = { 0x18,0x15,0x40,0x28,0xB2,0xF0,0x16,0x00,0x4C,0xF8,0x43,0x00,0xD0,0x3C,0x20,0x00,0x00,0x98} ;
// BYTE code DTD_2880x240_60P[] = { 0x18,0x15,0x40,0x28,0xB2,0xF0,0x16,0x00,0x4C,0xF8,0x43,0x00,0xD0,0x3C,0x20,0x00,0x00,0x18} ;
// BYTE code DTD_1440x480_60P[] = { 0x18,0x15,0xA0,0x14,0x51,0xE0,0x2D,0x10,0x20,0x7C,0x96,0x00,0x68,0x78,0x10,0x00,0x00,0x18} ;
BYTE code DTD_1920x1080_60P[] = { 0xF3,0x39,0x80,0x18,0x71,0x38,0x2D,0x40,0x58,0x2C,0x45,0x00,0xE0,0x0E,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_720x576_50P[] = { 0x8C,0x0A,0xD0,0x90,0x20,0x40,0x31,0x20,0x0C,0x40,0x55,0x00,0xB4,0x90,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_1280x720_50P[] = { 0x1A,0x1D,0x00,0xBC,0x52,0xD0,0x1E,0x20,0xB8,0x28,0x55,0x40,0x40,0xB4,0x10,0x00,0x00,0x1E} ;
BYTE code DTD_1920x1080_50I[] = { 0x1A,0x1D,0x80,0xD0,0x72,0x1C,0x16,0x20,0x10,0x2C,0x25,0x80,0xE0,0x87,0x10,0x00,0x00,0x9E} ;
// BYTE code DTD_720x576_50I[] = { 0x46,0x05,0xD0,0x90,0x20,0x20,0x18,0x10,0x0C,0x3F,0x23,0x00,0xB4,0x48,0x00,0x00,0x00,0x98} ;
// BYTE code DTD_1440x576_50I[] = { 0x8C,0x0A,0xA0,0x20,0x51,0x20,0x18,0x10,0x18,0x7E,0x23,0x00,0x68,0x48,0x10,0x00,0x00,0x98} ;
// BYTE code DTD_720x288_50P[] = { 0x46,0x05,0xD0,0x90,0x20,0x20,0x18,0x10,0x0C,0x3F,0x23,0x00,0xB4,0x48,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_1440x288_50P[] = { 0x8C,0x0A,0xA0,0x20,0x51,0x20,0x19,0x10,0x18,0x7E,0x33,0x00,0x68,0x48,0x10,0x00,0x00,0x18} ;
// BYTE code DTD_2880x576_50I[] = { 0x18,0x15,0x40,0x40,0xB2,0x20,0x18,0x10,0x30,0xFC,0x23,0x00,0xD0,0x48,0x20,0x00,0x00,0x98} ;
// BYTE code DTD_2880x288_50P[] = { 0x18,0x15,0x40,0x40,0xB2,0x20,0x18,0x10,0x30,0xFC,0x23,0x00,0xD0,0x48,0x20,0x00,0x00,0x18} ;
// BYTE code DTD_1440x576_50P[] = { 0x18,0x15,0xA0,0x20,0x51,0x40,0x31,0x20,0x18,0x80,0x55,0x00,0x68,0x90,0x10,0x00,0x00,0x1C} ;
BYTE code DTD_1920x1080_50P[] = { 0xD0,0x39,0x80,0xD0,0x72,0x38,0x2D,0x40,0x10,0x2C,0x45,0x80,0xE0,0x0E,0x11,0x00,0x00,0x1E} ;
BYTE code DTD_1920x1080_24P[] = { 0x1A,0x1D,0x80,0x3E,0x73,0x38,0x2D,0x40,0x7E,0x2C,0x45,0x80,0xE0,0x0E,0x11,0x00,0x00,0x1E} ;
BYTE code DTD_1920x1080_25P[] = { 0x1A,0x1D,0x80,0xD0,0x72,0x38,0x2D,0x40,0x10,0x2C,0x45,0x80,0xE0,0x0E,0x11,0x00,0x00,0x1E} ;
BYTE code DTD_1920x1080_30P[] = { 0x1A,0x1D,0x80,0x18,0x71,0x38,0x2D,0x40,0x58,0x2C,0x45,0x00,0xE0,0x0E,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_640x350_85P[] = { 0x4E,0x0C,0x80,0xC0,0x20,0x5E,0x5F,0x10,0x20,0x40,0x03,0x08,0xA0,0x57,0x00,0x00,0x00,0x1A} ;
// BYTE code DTD_640x400_85P[] = { 0x4E,0x0C,0x80,0xC0,0x20,0x90,0x2D,0x10,0x20,0x40,0x13,0x00,0xA0,0x64,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_832x624_75P[] = { 0x60,0x16,0x40,0x40,0x31,0x70,0x2B,0x20,0x20,0x40,0x13,0x00,0xD0,0x9C,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_720x350_70P[] = { 0x10,0x0B,0xD0,0xB4,0x20,0x5E,0x63,0x10,0x12,0x6C,0xB2,0x0C,0xB4,0x57,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_720x400_70P[] = { 0x10,0x0B,0xD0,0xB4,0x20,0x90,0x31,0x10,0x12,0x6C,0xD2,0x00,0xB4,0x64,0x00,0x00,0x00,0x1C} ;
// BYTE code DTD_720x400_85P[] = { 0xDE,0x0D,0xD0,0xD8,0x20,0x90,0x2E,0x10,0x24,0x48,0x13,0x00,0xB4,0x64,0x00,0x00,0x00,0x1C} ;
// BYTE code DTD_640x480_75P[] = { 0x4E,0x0C,0x80,0xC8,0x20,0xE0,0x14,0x10,0x10,0x40,0x13,0x00,0xA0,0x78,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_640x480_85P[] = { 0x10,0x0E,0x80,0xC0,0x20,0xE0,0x1D,0x10,0x38,0x38,0x13,0x00,0xA0,0x78,0x00,0x00,0x00,0x18} ;
// BYTE code DTD_800x600_56P[] = { 0x10,0x0E,0x20,0xE0,0x30,0x58,0x19,0x20,0x18,0x48,0x12,0x00,0xC8,0x96,0x00,0x00,0x00,0x1E} ;
// BYTE code DTD_800x600_60P[] = { 0xA0,0x0F,0x20,0x00,0x31,0x58,0x1C,0x20,0x28,0x80,0x14,0x00,0xC8,0x96,0x00,0x00,0x00,0x1E} ;
// BYTE code DTD_800x600_72P[] = { 0x88,0x13,0x20,0xF0,0x30,0x58,0x42,0x20,0x38,0x78,0x56,0x08,0xC8,0x96,0x00,0x00,0x00,0x1E} ;
// BYTE code DTD_800x600_75P[] = { 0x56,0x13,0x20,0x00,0x31,0x58,0x19,0x20,0x10,0x50,0x13,0x00,0xC8,0x96,0x00,0x00,0x00,0x1E} ;
// BYTE code DTD_800x600_85P[] = { 0xF9,0x15,0x20,0xF8,0x30,0x58,0x1F,0x20,0x20,0x40,0x13,0x00,0xC8,0x96,0x00,0x00,0x00,0x1E} ;
// BYTE code DTD_848x480_60P[] = { 0x2F,0x0D,0x50,0xF0,0x30,0xE0,0x25,0x10,0x10,0x70,0x68,0x00,0xD4,0x78,0x00,0x00,0x00,0x1E} ;
// BYTE code DTD_1024x768_87I[] = { 0x8A,0x11,0x00,0xF0,0x40,0x80,0x18,0x10,0x08,0xB0,0x04,0x00,0x00,0x60,0x10,0x00,0x00,0x9E} ;
// BYTE code DTD_1024x768_60P[] = { 0x64,0x19,0x00,0x40,0x41,0x00,0x26,0x30,0x18,0x88,0x36,0x00,0x00,0xC0,0x10,0x00,0x00,0x18} ;
// BYTE code DTD_1024x768_70P[] = { 0x4C,0x1D,0x00,0x30,0x41,0x00,0x26,0x30,0x18,0x88,0x36,0x00,0x00,0xC0,0x10,0x00,0x00,0x18} ;
// BYTE code DTD_1024x768_75P[] = { 0xC3,0x1E,0x00,0x20,0x41,0x00,0x20,0x30,0x10,0x60,0x13,0x00,0x00,0xC0,0x10,0x00,0x00,0x1E} ;
// BYTE code DTD_1024x768_85P[] = { 0xEA,0x24,0x00,0x60,0x41,0x00,0x28,0x30,0x30,0x60,0x13,0x00,0x00,0xC0,0x10,0x00,0x00,0x1E} ;
// BYTE code DTD_1152x864_75P[] = { 0x30,0x2A,0x80,0xC0,0x41,0x60,0x24,0x30,0x40,0x80,0x13,0x00,0x20,0xD8,0x10,0x00,0x00,0x1E} ;
// BYTE code DTD_1280x768_60PR[] = { 0xA9,0x1A,0x00,0xA0,0x50,0x00,0x16,0x30,0x30,0x20,0x37,0x00,0x40,0xC0,0x10,0x00,0x00,0x1A} ;
// BYTE code DTD_1280x768_60PW[] = { 0x0E,0x1F,0x00,0x80,0x51,0x00,0x1E,0x30,0x40,0x80,0x37,0x00,0x40,0xC0,0x10,0x00,0x00,0x1C} ;
// BYTE code DTD_1280x768_75P[] = { 0xF1,0x27,0x00,0xA0,0x51,0x00,0x25,0x30,0x50,0x80,0x37,0x00,0x40,0xC0,0x10,0x00,0x00,0x1C} ;
// BYTE code DTD_1280x768_85P[] = { 0xE6,0x2D,0x00,0xB0,0x51,0x00,0x29,0x30,0x50,0x88,0x37,0x00,0x40,0xC0,0x10,0x00,0x00,0x1C} ;
// BYTE code DTD_1280x960_60P[] = { 0x30,0x2A,0x00,0x08,0x52,0xC0,0x28,0x30,0x60,0x70,0x13,0x00,0x40,0xF0,0x10,0x00,0x00,0x1E} ;
// BYTE code DTD_1280x960_85P[] = { 0x02,0x3A,0x00,0xC0,0x51,0xC0,0x33,0x30,0x40,0xA0,0x13,0x00,0x40,0xF0,0x10,0x00,0x00,0x1E} ;
// BYTE code DTD_1280x1024_60P[] = { 0x30,0x2A,0x00,0x98,0x51,0x00,0x2A,0x40,0x30,0x70,0x13,0x00,0x40,0x00,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1280x1024_75P[] = { 0xBC,0x34,0x00,0x98,0x51,0x00,0x2A,0x40,0x10,0x90,0x13,0x00,0x40,0x00,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1280x1024_85P[] = { 0x86,0x3D,0x00,0xC0,0x51,0x00,0x30,0x40,0x40,0xA0,0x13,0x00,0x40,0x00,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1360x768_60P[] = { 0x66,0x21,0x50,0xB0,0x51,0x00,0x1B,0x30,0x40,0x70,0x36,0x00,0x54,0xC0,0x10,0x00,0x00,0x1E} ;
// BYTE code DTD_1400x1050_60PR[] = { 0x74,0x27,0x78,0xA0,0x50,0x1A,0x1E,0x40,0x30,0x20,0x34,0x00,0x5E,0x06,0x11,0x00,0x00,0x1A} ;
// BYTE code DTD_1400x1050_60PW[] = { 0x8F,0x2F,0x78,0xD0,0x51,0x1A,0x27,0x40,0x58,0x90,0x34,0x00,0x5E,0x06,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1400x1050_75P[] = { 0xF0,0x3C,0x78,0xF0,0x51,0x1A,0x31,0x40,0x68,0x90,0x34,0x00,0x5E,0x06,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1400x1050_85P[] = { 0x1E,0x46,0x78,0x00,0x52,0x1A,0x37,0x40,0x68,0x98,0x34,0x00,0x5E,0x06,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1440x900_60PR[] = { 0xAB,0x22,0xA0,0xA0,0x50,0x84,0x1A,0x30,0x30,0x20,0x36,0x00,0x68,0xE1,0x10,0x00,0x00,0x1A} ;
// BYTE code DTD_1440x900_60PW[] = { 0x9A,0x29,0xA0,0xD0,0x51,0x84,0x22,0x30,0x50,0x98,0x36,0x00,0x68,0xE1,0x10,0x00,0x00,0x1C} ;
// BYTE code DTD_1440x900_75P[] = { 0x6B,0x35,0xA0,0xF0,0x51,0x84,0x2A,0x30,0x60,0x98,0x36,0x00,0x68,0xE1,0x10,0x00,0x00,0x1C} ;
// BYTE code DTD_1440x900_85P[] = { 0x54,0x3D,0xA0,0x00,0x52,0x84,0x30,0x30,0x68,0x98,0x36,0x00,0x68,0xE1,0x10,0x00,0x00,0x1C} ;
BYTE code DTD_1600x1200_60P[] = { 0x48,0x3F,0x40,0x30,0x62,0xB0,0x32,0x40,0x40,0xC0,0x13,0x00,0x90,0x2C,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1600x1200_65P[] = { 0x8E,0x44,0x40,0x30,0x62,0xB0,0x32,0x40,0x40,0xC0,0x13,0x00,0x90,0x2C,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1600x1200_70P[] = { 0xD4,0x49,0x40,0x30,0x62,0xB0,0x32,0x40,0x40,0xC0,0x13,0x00,0x90,0x2C,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1600x1200_75P[] = { 0x1A,0x4F,0x40,0x30,0x62,0xB0,0x32,0x40,0x40,0xC0,0x13,0x00,0x90,0x2C,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1600x1200_85P[] = { 0xA6,0x59,0x40,0x30,0x62,0xB0,0x32,0x40,0x40,0xC0,0x13,0x00,0x90,0x2C,0x11,0x00,0x00,0x1E} ;
// BYTE code DTD_1680x1050_60PR[] = { 0x7C,0x2E,0x90,0xA0,0x60,0x1A,0x1E,0x40,0x30,0x20,0x36,0x00,0xA4,0x06,0x11,0x00,0x00,0x1A} ;
// BYTE code DTD_1680x1050_60PW[] = { 0x21,0x39,0x90,0x30,0x62,0x1A,0x27,0x40,0x68,0xB0,0x36,0x00,0xA4,0x06,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1680x1050_75P[] = { 0x0C,0x49,0x90,0x50,0x62,0x1A,0x31,0x40,0x78,0xB0,0x36,0x00,0xA4,0x06,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1680x1050_85P[] = { 0xE3,0x53,0x90,0x60,0x62,0x1A,0x37,0x40,0x80,0xB0,0x36,0x00,0xA4,0x06,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1792x1344_60P[] = { 0xFB,0x4F,0x00,0x90,0x72,0x40,0x32,0x50,0x80,0xC8,0x13,0x00,0xC0,0x50,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1792x1344_75P[] = { 0xF4,0x65,0x00,0x98,0x72,0x40,0x49,0x50,0x60,0xD8,0x13,0x00,0xC0,0x50,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1856x1392_60P[] = { 0x41,0x55,0x40,0xA0,0x72,0x70,0x2F,0x50,0x60,0xE0,0x13,0x00,0xD0,0x5C,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1856x1392_75P[] = { 0x80,0x70,0x40,0xC0,0x72,0x70,0x6C,0x50,0x80,0xE0,0x13,0x00,0xD0,0x5C,0x11,0x00,0x00,0x1C} ;
BYTE code DTD_1920x1200_60PR[] = { 0x28,0x3C,0x80,0xA0,0x70,0xB0,0x23,0x40,0x30,0x20,0x36,0x00,0xE0,0x2C,0x11,0x00,0x00,0x1A} ;
// BYTE code DTD_1920x1200_60PW[] = { 0x7D,0x4B,0x80,0xA0,0x72,0xB0,0x2D,0x40,0x88,0xC8,0x36,0x00,0xE0,0x2C,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1920x1200_75P[] = { 0xCD,0x5F,0x80,0xB0,0x72,0xB0,0x37,0x40,0x88,0xD0,0x36,0x00,0xE0,0x2C,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1920x1200_85P[] = { 0xDD,0x6D,0x80,0xC0,0x72,0xB0,0x3E,0x40,0x90,0xD0,0x36,0x00,0xE0,0x2C,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1920x1440_60P[] = { 0x68,0x5B,0x80,0xA8,0x72,0xA0,0x3C,0x50,0x80,0xD0,0x13,0x00,0xE0,0x68,0x11,0x00,0x00,0x1C} ;
// BYTE code DTD_1920x1440_75P[] = { 0x04,0x74,0x80,0xD0,0x72,0xA0,0x3C,0x50,0x90,0xE0,0x13,0x00,0xE0,0x68,0x11,0x00,0x00,0x1C} ;

#define EDID_Page_Size 16
#if 0
BYTE code Default_EDID0[] =
{
    0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
    0x26,0x85,0x06,0x65,0x00,0x00,0x00,0x00,
    0x1E,0x12,
              0x01,0x03,0x80,
                             0x3C,0x22,0x78,
    0x28,0x03,0x20,0xA7,0x55,0x45,0x96,0x24,
    0x11,0x49,0x4B,
                   0x21,0x08,0x00,
                                  0x01,0x01,
    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
    0x01,0x01,0x01,0x01,0x01,0x01,
#if 1
                                  0x64,0x19, // just enable 1024x768@60 as DTD.
    0x00,0x40,0x41,0x00,0x26,0x30,0x18,0x88,
    0x36,0x00,0x00,0xC0,0x10,0x00,0x00,0x18,
#else
    0x48,0x3F,0x40,0x30,0x62,0xB0,0x32,0x40,0x40,0xC0,0x13,0x00,0x90,0x2C,0x11,0x00,0x00,0x1E,//1600x1200
#endif
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,
              0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,
                        0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,
    #ifndef DISABLE_HDMI_EDID
                                  0x01,0x2F
    #else
                                  0x00,0x30
    #endif
};


/////////////////////////////////////////////////
//BLOCK 1 --HDMI--
/////////////////////////////////////////////////
#ifndef DISABLE_AUDIO_SUPPORT
#pragma message("Audio support EDID1.")
BYTE code Default_EDID1[] = {
#define USE_640x480
#ifdef USE_640x480
0x02,0x03,0x14,0x41,
0x41,0x81,
#else
0x02,0x03,0x15,0x41,
0x42,0x84,0x02,
#endif
0x23,0x09,0x07,0x07,
0x65,0x03,0x0c,0x00,0x10,0x00,
0x83,0x01,0x00,0x00,

#ifdef USE_640x480
0xD5,0x09,0x80,0xA0,0x20,0xE0,0x2D,0x10,0x10,0x60,0xA2,0x00,0xA0,0x78,0x00,0x00,0x00,0x18,
#else
0x1A, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20, 0x6E, 0x28, 0x55, 0x00, 0x40, 0xB4, 0x10, 0x00, 0x00, 0x1E,//1280x720p
#endif
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x25
};
//BYTE code Default_EDID1[] = {
//0x02,0x03,0x1a,0x41,
//0x47,0x90,0x04,0x03,0x02,0x07,0x16,0x01,
//0x23,0x09,0x07,0x07,
//0x65,0x03,0x0c,0x00,0x10,0x00,
//0x83,0x01,0x00,0x00,
//
//0x02,0x3a,0x80,0x18,0x71,0x38,0x2d,0x40,0x58,0x2c,0x45,0x00,0x07,0x44,0x21,0x00,0x00,0x1e,
//0x01,0x1d,0x00,0x72,0x51,0xd0,0x1e,0x20,0x6e,0x28,0x55,0x00,0x07,0x44,0x21,0x00,0x00,0x1e,
//0x8c,0x0a,0xd0,0x8a,0x20,0xe0,0x2d,0x10,0x10,0x3e,0x96,0x00,0x07,0x44,0x21,0x00,0x00,0x18,
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23
//};
// BYTE code weakDefault_EDID1[] = {
// 0x02,0x03,0x19,0x41,
// 0x46,0x84,0x03,0x02,0x07,0x16,0x01,
// 0x23,0x09,0x07,0x07,
// 0x65,0x03,0x0c,0x00,0x10,0x00,
// 0x83,0x01,0x00,0x00,
//
// 0x01,0x1d,0x00,0x72,0x51,0xd0,0x1e,0x20,0x6e,0x28,0x55,0x00,0x07,0x44,0x21,0x00,0x00,0x1e,
// 0x8c,0x0a,0xd0,0x8a,0x20,0xe0,0x2d,0x10,0x10,0x3e,0x96,0x00,0x07,0x44,0x21,0x00,0x00,0x18,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x23
// };
#else // DISABLE_AUDIO_SUPPORT
#pragma message("Audio not support EDID1.")
BYTE code Default_EDID1[] = {
0x02,0x03,0x10,0x01,
0x41,0x81,
0x65,0x03,0x0c,0x00,0x10,0x00,
0x83,0x01,0x00,0x00,

0xD5,0x09,0x80,0xA0,0x20,0xE0,0x2D,0x10,0x10,0x60,0xA2,0x00,0xA0,0x78,0x00,0x00,0x00,0x18,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0,0,0,0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x25
};
// BYTE code Default_EDID1[] = {
// 0x02,0x03,0x16,0x01,
// 0x47,0x90,0x04,0x03,0x02,0x07,0x16,0x01,
// 0x65,0x03,0x0c,0x00,0x10,0x00,
// 0x83,0x01,0x00,0x00,
//
// 0x02,0x3a,0x80,0x18,0x71,0x38,0x2d,0x40,0x58,0x2c,0x45,0x00,0x07,0x44,0x21,0x00,0x00,0x1e,
// 0x01,0x1d,0x00,0x72,0x51,0xd0,0x1e,0x20,0x6e,0x28,0x55,0x00,0x07,0x44,0x21,0x00,0x00,0x1e,
// 0x8c,0x0a,0xd0,0x8a,0x20,0xe0,0x2d,0x10,0x10,0x3e,0x96,0x00,0x07,0x44,0x21,0x00,0x00,0x18,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x23
// };
//
// BYTE code weakDefault_EDID1[] = {
// 0x02,0x03,0x16,0x01,
// 0x47,0x05,0x84,0x03,0x02,0x07,0x16,0x01,
// 0x65,0x03,0x0c,0x00,0x10,0x00,
// 0x83,0x01,0x00,0x00,
//
// 0x01,0x1d,0x00,0x72,0x51,0xd0,0x1e,0x20,0x6e,0x28,0x55,0x00,0x07,0x44,0x21,0x00,0x00,0x1e,
// 0x8c,0x0a,0xd0,0x8a,0x20,0xe0,0x2d,0x10,0x10,0x3e,0x96,0x00,0x07,0x44,0x21,0x00,0x00,0x18,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 0x23
// };
#endif // DISABLE_AUDIO_SUPPORT
#else
BYTE code Default_EDID0[] =
{
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0x26,0x85,0xAC,0x06,0x01,0x00,0x00,0x00,

0x34,0x13,0x01,0x03,0x80,0x66,0x39,0x78,
0x0A,0xEE,0x91,0xA3,0x54,0x4C,0x99,0x26,

0x0F,0x50,0x54,0xBD,0xEF,0x80,0x71,0x4F,
0x81,0x00,0x81,0x40,0x81,0x80,0x95,0x00,

0x95,0x0F,0xB3,0x00,0xA9,0x40,
                              0x02,0x3A,
0x80,0x18,0x71,0x38,0x2D,0x40,0x58,0x2C,
0x45,0x00,0xA0,0x5A,0x00,0x00,0x00,0x1E,

0x66,0x21,0x50,0xB0,0x51,0x00,0x1B,0x30,
0x40,0x70,0x36,0x00,0xA0,0x5A,0x00,0x00,
0x00,0x1E,

          0x00,0x00,0x00,0xFD,0x00,0x18,
0x4B,0x1A,0x51,0x17,0x00,0x0A,0x20,0x20,
0x20,0x20,0x20,0x20,

                    0x00,0x00,0x00,0xFC,
0x00,0x49,0x54,0x45,0x20,0x44,0x45,0x4D,
0x4F,0x20,0x20,0x20,0x20,0x20,
                              0x01,0x28,
};

BYTE code Default_EDID1[] =
{
0x02,0x03,0x33,0xF1,0x46,0x90,0x04,0x05,0x03,0x20,0x22,0x23,0x09,0x07,0x07,0x83,
0x01,0x00,0x00,0xE2,0x00,0x0F,0xE3,0x05,0x03,0x01,0x78,0x03,0x0C,0x00,0x10,0x00,
0xB8,0x2D,0x20,0xC0,0x0E,0x01,0x00,0x00,0x12,0x18,0x20,0x28,0x20,0x38,0x20,0x58,
0x20,0x68,0x20,0x01,0x1D,0x00,0x72,0x51,0xD0,0x1E,0x20,0x6E,0x28,0x55,0x00,0xA0,
0x5A,0x00,0x00,0x00,0x1E,0x01,0x1D,0x80,0x18,0x71,0x1C,0x16,0x20,0x58,0x2C,0x25,
0x00,0xA0,0x5A,0x00,0x00,0x00,0x9E,0x8C,0x0A,0xD0,0x8A,0x20,0xE0,0x2D,0x10,0x10,
0x3E,0x96,0x00,0xA0,0x5A,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF4,
};
#endif

#ifdef EDID_Dump
void DumpEDID(BYTE *dEDID)
{
    BYTE i;
    for(i=0;i<0x80;i++)
    {
        if((i%16)==0)
            EDID_DEBUG_PRINTF(("\n"));
        if(dEDID[i]<0x10)
            EDID_DEBUG_PRINTF(("0"));
        EDID_DEBUG_PRINTF(("%x  ",(WORD)dEDID[i]));
    }
    EDID_DEBUG_PRINTF(("\n"));
}
#endif


BYTE Read_OneBlock_EDID(BYTE *rEDID, BYTE uBlock, BYTE EDIDdev)
{

    BYTE i;
    BOOL EDID_Reading;

    BYTE CheckSum =0;

    for(i=0;i<0x80;i+=0x10)
    {             // Read EDID
        #ifdef On_Chip_EDID
        if(EDIDdev == ExtEDID)
        EDID_Reading=EDID_READ_BYTE(EXT_EDIDADR, i+(uBlock*0x80), 0x10,  &rEDID[i], EDIDdev);
        else
        #endif
        EDID_Reading=EDID_READ_BYTE(EDIDADR, i+(uBlock*0x80), 0x10,  &rEDID[i], EDIDdev);
        if(EDID_Reading== TRUE)
            continue;
        else
        {
            #ifdef EDID_Dump
            EDID_DEBUG_PRINTF(("Read EIDI[%x] = %x\n",(WORD)i,(WORD)rEDID[i]));
            #endif
            return Ext_EDID_Read_Fail;
        }
    }

    for(i=0;i<0x80;i++)
    {
        CheckSum+=rEDID[i];
    }
#ifdef EDID_Dump
        EDID_DEBUG_PRINTF(("========Read EDID Block %x ========\n",(WORD)uBlock));
        EDID_DEBUG_PRINTF(("CheckSum=%X\n",(WORD)CheckSum));
        DumpEDID(rEDID);
#endif
    if(CheckSum!=0)
    {
#ifdef EDID_Dump
        EDID_DEBUG_PRINTF(("================================\n"));
        EDID_DEBUG_PRINTF(("||                            ||\n"));
        EDID_DEBUG_PRINTF(("||                            ||\n"));
        EDID_DEBUG_PRINTF(("||   Check Sum Error          ||\n"));
        EDID_DEBUG_PRINTF(("||                            ||\n"));
        EDID_DEBUG_PRINTF(("||                            ||\n"));
        EDID_DEBUG_PRINTF(("================================\n"));
#endif
        return Int_EDID_CheckSum_Fail;
    }
    return EDID_Read_Success;				 // EDID OK return
}
void EDIDWP(BOOL wp)
{
    if(wp)
        EDID_WP=1;
    else
        EDID_WP=0;
}

BYTE Write_OneBlock_EDID(BYTE *wEDID, BYTE uBlock)
{
	BYTE i;
    EDIDWP(FALSE);
    //==================================================================
    wEDID[0x7F] = 0;
    for(i=0;i<0x7F;i++)
    {
        wEDID[0x7F] -= wEDID[i];
    }
#ifdef EDID_Dump
    EDID_DEBUG_PRINTF(("========EDID buf Data %x ========\n",(WORD)uBlock));
    DumpEDID(wEDID);
    //==================================================================
#endif
	for(i=0;i<0x80;i+=EDID_Page_Size)
    {
        BYTE cCheckLimCnt,cNumCnt,ByteAddress,ReadErrorCnt;
        BYTE cCheckData[EDID_Page_Size];
        BOOL bWriteSuccess;
        #ifdef EDID_Dump
        EDID_DEBUG_PRINTF1(("========EDID block-%x-%x========",(WORD)uBlock,(WORD)i));
        #endif
        cCheckLimCnt = 3;
        while(cCheckLimCnt--)
        {
            ByteAddress = i+(uBlock*0x80);
            ReadErrorCnt = 100;
        #ifdef On_Chip_EDID
            EDID_WRITE_BYTE( EDIDADR,ByteAddress ,EDID_Page_Size, &wEDID[i],  RXDEV);
            while(!EDID_READ_BYTE(EDIDADR,ByteAddress, EDID_Page_Size, cCheckData, RXDEV)&&(ReadErrorCnt))
                ReadErrorCnt--;
        #else
            EDID_WRITE_BYTE( EDIDADR,ByteAddress ,EDID_Page_Size, &wEDID[i],  IntEDID);
            delay1ms(8);//8
            while(!EDID_READ_BYTE(EDIDADR,ByteAddress, EDID_Page_Size, cCheckData, IntEDID)&&(ReadErrorCnt))
                ReadErrorCnt--;
        #endif
            for(cNumCnt=0;cNumCnt<EDID_Page_Size;cNumCnt++)
            {
                ByteAddress = i+cNumCnt;
                bWriteSuccess = TRUE;
                //EDID_DEBUG_PRINTF(("ByteAddress=%x\n",(WORD)ByteAddress));
                if(cCheckData[cNumCnt] == wEDID[ByteAddress]) continue;
                else
                {
                    #ifdef EDID_Dump
                    EDID_DEBUG_PRINTF(("cCheckData=%x vs EDID[%x]=%x\n",(WORD)cCheckData[cNumCnt],(WORD)ByteAddress,(WORD)wEDID[ByteAddress]));
                    #endif
                    bWriteSuccess = FALSE;
                    //break;
                }
            }
            if(bWriteSuccess) break;
        }
        #ifdef EDID_Dump
        if(bWriteSuccess==FALSE)
            EDID_DEBUG_PRINTF(("========can't write ========\n",(WORD)uBlock));
        else
            EDID_DEBUG_PRINTF(("\n"));
        #endif
	}
   // HoldSystem();
#ifdef EDID_Dump
    #ifdef On_Chip_EDID
    //==================================================================
    Read_OneBlock_EDID(wEDID, uBlock, RXDEV);
    //==================================================================
    #else
    //==================================================================
    Read_OneBlock_EDID(wEDID, uBlock, IntEDID);
    //==================================================================
    #endif
#endif
    EDIDWP(TRUE);
    return EDID_Write_Finish;
}

BYTE GetMeshCheckSum(BYTE *pEDIDBuff, int N)
{
    int i ;
    BYTE c, checksum ;

    for( i = 0, checksum = 0 ; i < N ; i++)
    {
        c = pEDIDBuff[i] ;
        EDID_DEBUG_PRINTF2(("c = %02X",(int)c)) ;
        c = rol8(c,i) ;
        EDID_DEBUG_PRINTF2(("-> %02X",(int)c)) ;
        EDID_DEBUG_PRINTF2(("MeshChecksum[%02X]: %02X",(int)i,(int)checksum)) ;
        checksum ^= c ;
        EDID_DEBUG_PRINTF2(("^%02X = %02X\n",(int)c,(int)checksum)) ;
    }

    return checksum ;
}


void EDID_1st_Block_Parsing(BYTE *v0EDID)
{

    BYTE i,k,flag;
    int Detailed_PCLK=0,j=0;

    v0EDID[0x12]= 0x01;
    v0EDID[0x13]= 0x03;
    v0EDID[0x14]= 0x80 ;

    EDID_DEBUG_PRINTF(("EDID_1st_Block_Parsing\n")) ;

    for(i=0x26;i<0x36;i+=2)
    {
        #ifdef DISABLE_STANDARD_TIMING
            v0EDID[i] = 1 ; v0EDID[i+1] = 1 ;
        #else
            if( v0EDID[i] < (80-31))
            {
                v0EDID[i] = 0x01 ;
                v0EDID[i+1] = 0x01 ;
            }
            else
            {
                if( (v0EDID[i+1] & 0x3F)>(85-60))
                {
                    v0EDID[i] = 0x01 ;
                    v0EDID[i+1] = 0x01 ;
                }
            }
        #endif
    }
}

void CopyDefaultEDID_0()
{
    xdata BYTE bEDID[0x80];
    BYTE i,checksum;
    checksum = 0 ;
    for(i=0;i<0x7F;i++)
    {
        bEDID[i] = Default_EDID0[i];
        checksum -= bEDID[i] ; checksum &= 0xFF ;
    }
    bEDID[0x7F] = checksum ;
    #ifdef EDID_Dump
    EDID_DEBUG_PRINTF(("CopyDefaultEDID_0\n"));
    #endif
    Write_OneBlock_EDID(bEDID, 0);                   // 032509 Clive
}

void CopyDefaultEDID_1()
{
    xdata BYTE aEDID[0x80];
    BYTE i,checksum;

    checksum = 0 ;
    for(i=0;i<0x7F;i++)
    {
        aEDID[i] = Default_EDID1[i];
        checksum -= aEDID[i] ; checksum &= 0xFF ;
    }
    aEDID[0x7F] = checksum ;
    #ifdef EDID_Dump
    EDID_DEBUG_PRINTF(("CopyDefaultEDID_1()\n"));
    #endif
    Write_OneBlock_EDID(aEDID, 1);                   // 061709 Clive
}

void CopyDefaultEDID()
{
    CopyDefaultEDID_0();
    CopyDefaultEDID_1();
}

#endif // _COPY_EDID_

